package com.otto.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.otto.reggie.common.R;
import com.otto.reggie.entity.Employee;
import com.otto.reggie.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * 作者：otto
 * 时间：2022-07-19 16:52:15
 */
@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @PostMapping("/login")
    public R<Employee> login(HttpServletRequest request, @RequestBody Employee employee) {
        return employeeService.login(request, employee);
    }

    @PostMapping("/logout")
    public R<String> logout(HttpServletRequest request) {
        return employeeService.logout(request);
    }

    @PostMapping
    public R<String> add(HttpServletRequest request, @RequestBody Employee employee) {
        return employeeService.add(request, employee);
    }

    /**
     * 员工信息分页查询
     *
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public R<Page> employeelist(int page, int pageSize, String name) {
        return employeeService.page(page, pageSize, name);
    }

    /**
     * 启用or禁用员工账号
     *
     * @param e
     * @return
     */
    @PutMapping()
    public R<String> start(HttpServletRequest request, @RequestBody Employee e) {
        return employeeService.update(request, e);
    }

    /**
     * 根据id查询员工信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<Employee> getById(@PathVariable Long id) {
        return employeeService.getById1(id);
    }
}
